package com.aidex.web.controller.biz;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.JdkyOrder;
import com.aidex.biz.service.JdkyOrderService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 京东订单推送Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/biz/bizJdkyOrder")
public class JdkyOrderController extends BaseController
{
    @Autowired
    private JdkyOrderService jdkyOrderService;

    /**
     * 查询京东订单推送列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:list')")
    @GetMapping("/list")
    public R<PageInfo> list(JdkyOrder jdkyOrder, HttpServletRequest request, HttpServletResponse response)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            jdkyOrder.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
         }
        jdkyOrder.setPage(new PageDomain(request, response));
        return R.data(jdkyOrderService.findPage(jdkyOrder));
    }

    /**
     * 获取京东订单推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:query')")
    @GetMapping(value = "/{id}")
    public R<JdkyOrder> detail(@PathVariable("id") String id)
    {
        return R.data(jdkyOrderService.get(id));
    }

    /**
     * 新增京东订单推送
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:add')")
    @Log(title = "京东订单推送", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  JdkyOrder jdkyOrder)
    {
        return R.status(jdkyOrderService.save(jdkyOrder));
    }

    /**
     * 修改京东订单推送
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:edit')")
    @Log(title = "京东订单推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated JdkyOrder jdkyOrder)
    {
        return R.status(jdkyOrderService.save(jdkyOrder));
    }


    /**
     * 删除京东订单推送
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:remove')")
    @Log(title = "京东订单推送", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(jdkyOrderService.deleteJdkyOrderByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(jdkyOrderService.findMaxSort(new JdkyOrder()));
    }

    /**
     * 导出京东订单推送列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizJdkyOrder:export')")
    @Log(title = "京东订单推送", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(JdkyOrder jdkyOrder)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    jdkyOrder.setCompanyId(null);
            }else{
                         jdkyOrder.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<JdkyOrder> list = jdkyOrderService.findList(jdkyOrder);
        ExcelUtil<JdkyOrder> util = new ExcelUtil<JdkyOrder>(JdkyOrder.class);
        return util.exportExcel(list, "京东订单推送数据");
    }

}
